<template>
  <div id="main" style="width: 100%; height: 100%"></div>
</template>

<script>
import * as echarts from "echarts";
require("echarts/theme/macarons"); // echarts theme
import resize from "../../dashboard/mixins/resize";

export default {
  mixins: [resize],
  props: {
    className: {
      type: String,
      default: 'chart'
    },
    width: {
      type: String,
      default: '100%'
    },
    height: {
      type: String,
      default: '300px'
    }
  },
  data() {
    return {
      chart: null
    }
  },
  mounted() {
    this.$nextTick(() => {
      this.initChart()
    })
  },
  beforeDestroy() {
    if (!this.chart) {
      return
    }
    this.chart.dispose()
    this.chart = null
  },
  methods: {
    initChart() {
      this.chart = echarts.init(this.$el, 'macarons')

      this.chart.setOption ({
        title: {
          text: '用水方便程度'
          // subtext: 'Fake Data'
        },
        tooltip: {
          trigger: 'axis'
        },
        // legend: {
        //   data: ['Rainfall']
        // },
        toolbox: {
          show: true,
          feature: {
            dataView: { show: true, readOnly: false },
            magicType: { show: true, type: ['line', 'bar'] },
            restore: { show: true },
            saveAsImage: { show: true }
          }
        },
        calculable: true,
        xAxis: [
          {
            type: 'category',
            // prettier-ignore
            data: ['8.3', '8.4', '8.5', '8.6', '8.7', '8.8']
          }
        ],
        yAxis: [
          {
            type: 'value',
            max: 24
          }
        ],
        series: [
          {
            name: 'Rainfall',
            type: 'bar',
            data: [2.0, 4.9, 14.0, 20.2, 23, 0],
            markPoint: {
              data: [
                { type: 'max', name: 'Max' },
                { type: 'min', name: 'Min' }
              ]
            },
            markLine: {
              symbol: ['circle', 'none'], // none为标线两端的样式为无，可更改
              data: [
                {
                  silent: false,
                  yAxis: 3,  // 警戒线位置，这个赋值为纵轴50
                  // label: {
                  //   position: 'end', // 文字位置
                  //   formatter: '标准供给时长',  //文字
                  //   color: 'green'  // 文字颜色
                  // },
                  lineStyle: { type: 'dashed', color: 'white', width: 2 } // 样式： 线型、颜色、线宽
                }
              ]
            }

          }
        ]
      });
    }
  }
}
</script>

